<?php
class AdWidget extends Widget{
	public function render($data){
		$ad = M('Ad');
		$info = $ad->where(array('id'=>$data,'status'=>1))->find();
		$content = '';
		switch($info['ad_type']){
			case 1: //图片
			if($info['nofollow'] == 1){
				$content = "<a rel='nofollow' target='_blank' href='{$info['pic_url']}' title='{$info['pic_title']}'><img src='{$info['pic']}' alt='{$info['pic_title']}' /></a>";
			}else{
				$content = "<a target='_blank' href='{$info['pic_url']}' title='{$info['pic_title']}'><img src='{$info['pic']}' alt='{$info['pic_title']}' /></a>";
			}
			break;
			case 2: //flash
			$pic   = explode('|', $info['flash']);
			$title = explode('|', $info['flash_title']);
			$url   = explode('|', $info['flash_url']);
			$nofollow   = explode('|', $info['nofollow']);
			$row_sort   = explode('|', $info['row_sort']);
			
			foreach($pic as $k=>$v){
				$ads[$k]['pic'] = $v;
				$ads[$k]['title'] = $title[$k];
				$ads[$k]['url'] = $url[$k];
				$ads[$k]['nofollow'] = $nofollow[$k];
				$ads[$k]['row_sort'] = $row_sort[$k];
			}
			if(C('ON_MOBILE') && isMobile()){
				$content =	$this->renderFile('slide/slide1', array('ad'=>$ads));
			}else{
				$content =	$this->renderFile('slide/slide3', array('ad'=>$ads));
			}
				break;
			case 3:
			$content = htmlspecialchars_decode($info['text']);
				break;
		}
		return $content;
	}
}

?>